#include<stdio.h>
int main(int argc, char const *argv[])
{
    int n,k,x,y,cc,pc,g;
    printf("Move Mountain Game\n");
    printf("GAME BEGIN\n");
    pc=cc=0;
    g=1;
    for(;;)
    {
        printf("No.%2d game \n",g++);
        printf("-----------------\n");
        printf("How many mountains are there ?");
        scanf("%d",&n);
        if(!n)
            break;
        printf("How many mountains are allowed to each time ?");
        do
        {
            scanf("%d",&k);
            if(k>n||k<1)
                printf("Repeat again!\n");
        } while (k>n||k<1);
        do
        {
            printf("How many mountains do you wish to move away ?");
            scanf("%d",&x);
            if(x<1||x>k||x>n)
            {
                printf("legal,again please!\n");
                continue;
            }
            n-=x;
            printf("There are %d mountains left now. \n",n);
            if(!n)
            {
                printf("---------I Win.You are failure.----------\n\n");
                cc++;
            }
            else
            {
                y=(n-1)%(k+1);
                if(!y)
                    y=1;
                    n-=y;
                    printf("Computer move %d mountains away. \n",y);
                if(n)
                    printf("There are %d mountains left now. \n",n);
                else
                {
                    printf("-----------i am failure,you win-------\n\n");
                    pc++;
                }
            }
        } while (n);        
    }
    printf("'Games in total have been played %d.\n",cc+pc);
    printf("Your score is win %d , lose %d.\n",pc,cc);
    printf("My score is win %d , lose %d.\n",cc,pc);
    return 0;
}
